package com.fqdf.framework.android.view.recycleviewdivider;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * @desc 线性recycleview间距，其中间距都是采用透明
 */
public class HorizontalLineSpacingDecoration extends RecyclerView.ItemDecoration {

    private int space;

    public HorizontalLineSpacingDecoration(int space) {
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {

        // Add top margin only for the first item to avoid double space between items
        if (parent.getChildLayoutPosition(view) == parent.getChildCount()) {
            outRect.right = 0;
        } else {
            outRect.right = space;
        }
    }
}
